package com.sqkj.dao;

import com.sqkj.entity.ArticleStar;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface ArticleStarDao {
    //增加一个点赞
    @Insert("insert into articlestar (userId,articleId,status) values (#{userId},#{articleId},#{status})")
    public int addStar(ArticleStar articleStar);
    //点赞
    @Update("update articlestar set status=1 where userId=#{userId} and articleId=#{articleId}")
    public int giveStar(@Param("userId")int userId,@Param("articleId")int articleId);
    //取消点赞
    @Update("update articlestar set status=0 where userId=#{userId} and articleId=#{articleId}")
    public int removeStar(@Param("userId")int userId,@Param("articleId")int articleId);
    //查询是否此用户是否点赞过此文章
    @Select("select * from articlestar where userId=#{userId} and articleId=#{articleId}")
    public ArticleStar findByUserIdAndArticleId(@Param("userId")int userId,@Param("articleId")int articleId);
    //如果用户点赞过,查询此条点赞的状态码0为取消点赞状态,1为点赞状态
    @Select("select status from articlestar where userId =#{userId} and articleId=#{articleId}")
    public int findStarStatus(@Param("userId")int userId,@Param("articleId")int articleId);
    @Select("select articleId from articlestar where userId = #{userId} and status = 1")
    public List<Integer> findMyselfStar(@Param("userId")int userId);
}
